/*
 *
 */
package org.lt.cj.core.filters;

import java.util.ArrayList;
import java.util.List;
import org.lt.cj.core.utils.HttpAccesser;

/*
 * @author luohong
 */
public class CustomFilter {

    private String text;

    public CustomFilter() {
    }

    public List<String> filt() {

        /* 取出脚本里面的http链接 */
        String filtText = this.text;
        String beginText = "g_hubble_item_desc_requested = +new Date();})('";
        String endText = "'";
        int beginIndex = filtText.indexOf(beginText) + beginText.length();
        int endIndex = filtText.indexOf(endText, beginIndex);
        String httpAddr = filtText.substring(beginIndex, endIndex);
        /* 取得链接里面的html内容并用<div>标签包装 */
        HttpAccesser accesser = HttpAccesser.getInstance();
        String result = accesser.accessWebPage(httpAddr);

        beginIndex = result.indexOf("var desc='") + "var desc='".length();
        endIndex = result.lastIndexOf("'");
        result = "<div>" + result.substring(beginIndex, endIndex) + "</div>";
        HierPathFilter filter = new HierPathFilter(result, "UTF-8");

        List<String> pathList = new ArrayList();
        pathList.add("img src=");
        //抽出图片并保存
        pathList = filter.filtPhoto(pathList, FilterConstans.contentsEvery);

        return pathList;
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }
}
